var form, laydate, upload, table;
var userName = "";
var wfId = RequestURLParam.getParam("wfId") || parent.$("#viewForm").attr("wfId") || "";
var taskkeyId = RequestURLParam.getParam("taskkeyId") || parent.$("#viewForm").attr("taskkeyId") || "";
var wfTaskId = RequestURLParam.getParam("wfTaskId") || parent.$("#viewForm").attr("wfTaskId") || "";
var activityId = RequestURLParam.getParam("activityId") || parent.$("#viewForm").attr("activityId") || "";
var taskId = RequestURLParam.getParam("taskId") || parent.$("#viewForm").attr("taskId") || "";

$(document).ready(function () {
    layui.use(['form', 'laydate', 'table', 'upload'], function () {
        form = layui.form;
        laydate = layui.laydate;
        table = layui.table;
        upload = layui.upload;

        form.verify({
            required: function (value) {
                if (value.length == 0) {
                    return '请输入内容！';
                }
            },
            number: function (value) {
                var patt1 = new RegExp(/^[0-9]*$/);
                if (!patt1.test(value)) {
                    return '必须输入数字'
                }
            },
            date: function (value) {
                var patt1 = new RegExp(/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/);
                if (!patt1.test(value)) {
                    return '请输入日期，格式为YYYY-MM-DD'
                }
            }
        });

        init_Data();
    });
});

function init_Data() {
    $.post("/wf/workflow/application/getFormDesignPrivilege",
        {
            "wfId": wfId,
            "taskId": taskId,
            "taskkeyId": taskkeyId,
            "activityId": activityId,
            "editFlag": 1
        },
        function (data) {
            if (data.OK == "OK") {
                // console.log(data.data)
                $('form').append(data.data);

                $(".money").blur(function(){
                    $(this).val(moneyFormat(parseInt($(this).val())))
                })


                $("input[ext-type='date']").each(function () {
                    laydate.render({
                        elem: this,
                        type: 'date'
                    })
                })

                $("input[ext-type='datetime']").each(function () {
                    laydate.render({
                        elem: this,
                        type: 'datetime'
                    })
                })

                if ($('[ext-type="img"]').length > 0) {
                    loadImg();
                }

                if ($('[ext-type="file"]').length > 0) {
                    loadFile();
                }

                if ($('[ext-type="datagrid"]').length > 0) {
                    loadTable();
                }

                $("#selectWF").on("click", function (data) {
                    selectWF();
                });

                $("#closeWF").on("click", function (data) {
                    closeWF();
                });

                if ($('table[ext-type="suggestion"]').length > 0) {
                    $('table[ext-type="suggestion"]').each(function () {
                        var name = $(this).attr("name");
                        var val = $('#' + name).val();

                        if($(this).find("textarea[ obj-type='opinion']").prop("disabled")){
                            $(this).find("textarea[ obj-type='opinion']").parent().parent().parent().hide();
                            $(this).find("textarea[ obj-type='opinion']").parent().parent().parent().next().hide();
                            $(this).find("textarea[ obj-type='opinion']").parent().parent().parent().prev().hide();
                        }

                        if (val != null && val != undefined && val != "") {
                            var obj = JSON.parse(val);

                            if (obj != null && obj != "" && obj.length >= 1) {
                                var th = $(['<tr id="' + name + 'head' + '">'
                                    , '<th style="border: 1px solid black">意见</th>'
                                    , '<th style="border: 1px solid black">详细意见</th>'
                                    , '<th style="border: 1px solid black">审批人</th>'
                                    , '<th style="border: 1px solid black">审批时间</th>'
                                    , '</tr>'].join(''));
                                $(this).find('tbody').prepend(th);
                            }
                            obj.forEach(function (data, index) {
                                if (data != null) {
                                    var tr = $(['<tr style="text-align: center">'
                                        , '<td style="border: 1px solid black">' + data.radio
                                        , '</td>'
                                        , '<td style="border: 1px solid black">' + data.text
                                        , '</td>'
                                        , '<td style="border: 1px solid black">' + data.user
                                        , '</td>'
                                        , '<td style="border: 1px solid black">' + data.time
                                        , '</td>'
                                        , '</tr>'].join(''));

                                    $('#' + name + "head").after(tr)
                                }
                            });
                        }
                    });
                }

                renderClickEvent();
                renderDefaultValue();
                renderBindingData();
                // renderOthers();


                if(!taskkeyId){
                    $("[lay-filter='formCheck']").each(function () {
                        var eventMask = $(this).attr("name")
                        if(eventMask=="revoke"||eventMask=="goto"){
                            $(this).css("display", "none");
                        }
                    });
                }
                form.render();
            } else {
                layer.msg('取得模块失败！', {
                    icon: 2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                })
            }
        }
    );
}

var form = layui.form;

form.on('submit(formCheck)', function () {
    var eventMask = $(this).attr("name")
    var layer = layui.layer

    switch (eventMask) {
        case 'save':
            url = "/wf/systask/key/save";
            title = '保存';
            break;
        case 'submit':
            url = "/wf/systask/key/submit";
            title = '提交';
            break;
        case 'revoke':
            url = "/wf/systask/key/revoke";
            title = '撤销';
            break;
        case 'goto':
            url = "tiaozhuang";
            title = '跳转';
            break;
        case 'back':
            url = "/wf/systask/key/goback";
            title = '退回';
            break;
    }

    layer.confirm('确定要进行' + title + '操作？', {icon: 3}, function (iindex) {
        formEventExecute(url, title)
        layer.close(iindex);
    });


    return false;
});

function formEventExecute(url, title, type) {

    var requestObj = new Object();
    var jsonObj = new Object();
    var jsonObjs = new Array();
    var tempObjs = new Array();
    var arrTemp = []
    var arrTemp1 = []

    var tempName, tempValue;


    //检测表单是否有 自定义编码字段 ， 并对应取得编码字段的值
    if(taskId==''||taskId==null) {
        replaceObjCode()
    }

    // tag转换为Object值
    /*
    * 修改对象结构
    * {
    * name
    * nameCn
    * value
    * valueId
    * tagType
    * dicId
    * objType
    * }
    *
    * */
    $('input[type=text], input[type=hidden], input[type=number], textarea').each(function () {
        tempName = $(this).attr('name');
        if ($(this).attr('name')) {
            if (tempName == 'wfId' ||
                tempName == 'taskId' ||
                tempName == 'taskkeyId' ||
                tempName == 'oldopinion' ||
                tempName == 'activityId') {
                requestObj[$(this).attr('name')] = $(this).val();
            } else {
                if ($(this).val()) arrTemp.push($(this).val());
                if ($(this).attr('value-code')) arrTemp1.push($(this).attr('value-code'));
                if ($(this).attr('obj-type') == "opinion") {
                    var opinion = $(this).parent().parent().parent().parent().parent().attr("name");
                    jsonObjs.push({
                        "name": $(this).attr('name'),
                        "nameCn": $(this).attr('cn-name'),
                        "values": arrTemp,
                        "valueCodes": arrTemp1,
                        "tagType": $(this).attr('ext-type'),
                        "dicId": $(this).attr('dic-id'),
                        "objType": $(this).attr('obj-type') || "",
                        "opinion": opinion
                    })
                } else if ($(this).attr('ext-type') == "todouser") {
                    jsonObjs.push({
                        "name": $(this).attr('name'),
                        "nameCn": $(this).attr('cn-name'),
                        "values": arrTemp,
                        "valueCodes": arrTemp1,
                        "tagType": "text",
                        "objType": $(this).attr('ext-type') || "",
                        "dicId": $(this).attr('dic-id'),
                    })
                } else {
                    jsonObjs.push({
                        "name": $(this).attr('name'),
                        "nameCn": $(this).attr('cn-name'),
                        "values": arrTemp,
                        "valueCodes": arrTemp1,
                        "tagType": "text",
                        "dicId": $(this).attr('dic-id'),
                    })
                }

                arrTemp = []
                arrTemp1 = []

            }
        }
    });


    var tempValue = [];
    var valueCode = []
    var oldKey = '';
    var cnName = ''
    var obj;
    var dicId;
    var tagType;
    $('div.layui-form-radioed').each(function () {
        obj = $(this).prev();

        if (obj.attr('obj-type') == "opinion") {
            var opinion = obj.parent().parent().parent().parent().parent().attr("name");
            tagType = obj.prop("tagName");
            if (tagType == "INPUT") {
                tagType = obj.prop("type");
            }
            cnName = obj.attr('cn-name');
            dicId = obj.attr('dic-value');
            oldKey = obj.attr('name');
            if (obj.val()) {
                tempValue.push(obj.val().split(":")[1]);
                valueCode.push(obj.val().split(":")[0]);
            }
            jsonObjs.push({
                "name": oldKey,
                "nameCn": cnName,
                "values": tempValue,
                "valueCodes": valueCode,
                "tagType": tagType.toLowerCase(),
                "dicId": dicId,
                "objType": obj.attr('obj-type') || "",
                "opinion": opinion
            });
            oldKey = '';
            tempValue = [];
            valueCode = [];
        } else {
            tagType = obj.prop("tagName");
            if (tagType == "INPUT") {
                tagType = obj.prop("type");
            }
            cnName = obj.attr('cn-name');
            dicId = obj.attr('dic-value');
            oldKey = obj.attr('name');
            if (obj.val()) {
                tempValue.push(obj.val().split(":")[1]);
                valueCode.push(obj.val().split(":")[0]);
            }
            jsonObjs.push({
                "name": oldKey,
                "nameCn": cnName,
                "values": tempValue,
                "valueCodes": valueCode,
                "tagType": tagType.toLowerCase(),
                "dicId": dicId,
            });
            oldKey = '';
            tempValue = [];
            valueCode = [];
        }
    });

    var check = [];
    $('input[type="checkbox"]').each(function () {
        var name = $(this).attr("name");
        tagType = $(this).prop("type");
        var flag = true;
        if (check.length > 0) {
            try {
                check.forEach(function (item, index) {
                    if (item == name) {
                        flag = false;
                        throw new Error("EndIterative");
                    }
                });
            } catch (e) {
                if (e.message != "EndIterative") throw e;
            }
            ;
        }

        if (flag) {
            check.push(name);
        }
    });

    check.forEach(function (value) {
        $('div.layui-form-checked').each(function () {
            obj = $(this).prev();
            var name = obj.attr('name');
            if (name == value) {
                dicId = obj.attr('dic-value');
                oldKey = obj.attr('name');
                if (obj.val()) {
                    tempValue.push(obj.val().split(":")[1]);
                    valueCode.push(obj.val().split(":")[0]);
                }
            }
        });

        jsonObjs.push({
            "name": oldKey,
            "nameCn": cnName,
            "values": tempValue,
            "valueCodes": valueCode,
            "tagType": tagType.toLowerCase(),
            "dicId": dicId,
        });

        tempValue = [];
        valueCode = [];
    });
    $('dd.layui-this').each(function () {
        if ($(this).parent().parent().hasClass("layui-form-select")) {
            obj = $(this).parent().parent().prev();

            tagType = obj.prop("tagName");
            cnName = obj.attr('cn-name');
            dicId = obj.attr('dic-value');
            oldKey = obj.attr('name');
            if (obj.val()) {
                tempValue.push(obj.val().split(":")[1])
                valueCode.push(obj.val().split(":")[0])
            }
            jsonObjs.push({
                "name": oldKey,
                "nameCn": cnName,
                "values": tempValue,
                "valueCodes": valueCode,
                "tagType": tagType.toLowerCase(),
                "dicId": dicId
            })
            tempValue = []
            valueCode = []
        }
    });

    //获取数据表格
    $('table[ext-type="datagrid"]').each(function () {
        if ($(this).prop("tagName") == "TABLE") {
            tagType = 'table';
        }
        var tabledata = JSON.stringify(table.cache[$(this).attr("id")]);
        jsonObjs.push({
            "name": $(this).attr("name"),
            "nameCn": $(this).attr("cn-name"),
            "values": [tabledata],
            "valueCodes": [],
            "tagType": tagType.toLowerCase()
        });
    });

    //获取图片
    $('button[ext-type="img"]').each(function () {
        tagType = 'img';
        var id = $(this).attr("id");
        var fid = $("#" + id + "Fid").val();
        var value = [];
        if ($(this).prop("disabled")) {
            value = [];
        } else {
            value = ["\"" + fid + "\""];
        }
        jsonObjs.push({
            "name": $(this).attr("name"),
            "nameCn": $(this).attr("cn-name"),
            "values": value,
            "valueCodes": [],
            "tagType": tagType.toLowerCase()
        });
    });

    //获取文件
    $('button[ext-type="file"]').each(function () {
        tagType = 'file';
        var id = $(this).attr("id");
        var fids = [];
        $('[name="' + id + "Fid" + '"]').each(function () {
            var fid = $(this).val();
            fids.push(fid);
        });
        jsonObjs.push({
            "name": $(this).attr("name"),
            "nameCn": $(this).attr("cn-name"),
            "values": fids,
            "valueCodes": [],
            "tagType": tagType.toLowerCase()
        });
    });

    var opinion = new Array();
    $('table[ext-type="suggestion"]').each(function () {
        var name = $(this).attr("name");
        var disabled = $(this).find('textarea[obj-type="opinion"]').prop("disabled");
        var old = $("#" + name).val();
        if (old == undefined || old == "") {
            old = "[]";
        }
        var op = JSON.parse(old);
        var oldOpinion = new Array();
        if (op.length > 0) {
            op.forEach(function (data) {
                oldOpinion.push(JSON.stringify(data));
            });
        }

        opinion.push({
            "name": name,
            "nameCn": "",
            "values": [],
            "valueCodes": [],
            "objType": "opinion",
            "oldOpinion": oldOpinion,
            "newOpinion": []
        })
    });

    jsonObjs.forEach(function (item, index) {
        if (item.objType == "opinion") {
            opinion.forEach(function (value, index1) {
                var disabled = $('table[name='+ value.name +']').find('textarea[obj-type="opinion"]').prop("disabled");
                if (value.name == item.opinion && !disabled) {
                    value.newOpinion.push(item);
                }
            })
        } else {
            tempObjs.push(item);
        }
    });

    var oldOpinion = {
        "radio": "",
        "text": "",
        "user": "",
        "time": "",
    };

    opinion.forEach(function (value, index) {
        var disabled = $('table[name='+ value.name +']').find('textarea[obj-type="opinion"]').prop("disabled");
        if(!disabled){
            value.newOpinion.forEach(function (value1, index1) {
                if (value1.tagType == "radio") {
                    oldOpinion.radio = value1.values[0] == undefined ? "" : value1.values[0];
                } else if (value1.tagType == "textarea") {
                    oldOpinion.text = value1.values[0] == undefined ? "" : value1.values[0];
                } else if (value1.tagType == "text") {
                    oldOpinion.user = value1.values[0] == undefined ? "" : value1.values[0];
                } else if (value1.tagType == "datetime") {
                    oldOpinion.time = value1.values[0] == undefined ? "" : value1.values[0];
                }
            });

            var olds = new Array();
            if (value.oldOpinion.length > 0) {
                var flag = true;
                value.oldOpinion.forEach(function (data) {
                    var old = JSON.parse(data);
                    if (old.user == oldOpinion.user) {
                        flag = false;
                        if(!(oldOpinion.radio == "" && oldOpinion.text == "")){
                            olds.push(JSON.stringify(oldOpinion));
                        }else{
                            olds.push(data);
                        }
                    } else {
                        olds.push(data);
                    }
                });
                if (flag) {
                    olds.push(JSON.stringify(oldOpinion));
                }
            } else {
                olds.push(JSON.stringify(oldOpinion));
            }

            value.oldOpinion = olds;
        }
    });

    opinion.forEach(function (value, index1) {
        tempObjs.push(value);
    })

    requestObj.wfRecord = JSON.stringify(tempObjs);
    requestObj.wfTaskId=wfTaskId;
    var abc = JSON.stringify(requestObj);
    if (url == "tiaozhuang") {
        $.ajax({
            url: '/wf/systask/key/save',
            timeout: 10000, //超时时间设置，单位毫秒
            type: 'post',
            async: false,
            data: {
                recieverInfo: abc
            },
            traditional: true,
            success: function (data) {
                if (data.OK == "OK") {
                    wfNull();
                } else {
                    layer.msg('流程操作失败！', {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                    })
                }
            },
            error: function (data) {
                layer.msg('流程操作失败！', {
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                })

            }
        });
    } else {
        $.ajax({
            url: url,
            timeout: 10000, //超时时间设置，单位毫秒
            type: 'post',
            async: false,
            data: {
                recieverInfo: abc
            },
            traditional: true,
            success: function (data) {
                if (data.OK == "OK") {
                    if (data.wfState == "NO") {
                        wfNull();
                    }
                    else if (data.wfState == "DUO") {
                        if(data.wfTargetList!=""&&data.wfTargetList!=null) {
                            wfDuo(data.wfTargetList);
                        }
                        else{
                            layer.alert('流程异常！所找到的环节均没有办理人员！请尽快联系管理人员！', {
                                    icon: 1
                                }, function (i) {
                                    layer.close(i);
                                    location.reload()
                                    if (parent.$("#spsp").length > 0) {
                                        parent.layer.close(parent.$("#spsp").val())
                                        parent.location.reload()
                                    }
                                }
                            )
                        }
                    }
                    else if (data.wfState == "bin") {
                        layer.alert('流程' + title + '成功！该环节操作类型为并行，其他人审批完该环节时才会进行下一环节！', {
                                icon: 1
                            }, function (i) {
                                layer.close(i);
                                location.reload()
                                if (parent.$("#spsp").length > 0) {
                                    parent.layer.close(parent.$("#spsp").val())
                                    parent.location.reload()
                                }
                            }
                        )

                    } else if (data.wfState == "chuan") {
                        layer.alert('流程' + title + '成功！该环节操作类型为串行！下一办理人是' + data.operatorList[1].userName, {
                                icon: 1
                            }, function (i) {
                                layer.close(i);
                                location.reload()
                                if (parent.$("#spsp").length > 0) {
                                    parent.layer.close(parent.$("#spsp").val())
                                    parent.location.reload()
                                }
                            }
                        )
                    }
                    else {
                        var userName = "";
                        if (data.operatorList != '' && data.operatorList != undefined) {
                            for (var i = 0; i < data.operatorList.length; i++) {
                                userName = userName + data.operatorList[i].userName + " ";
                            }

                            layer.alert('流程' + title + '成功！申请已发送至【' + data.wfActivity.activityName + '】环节，并对用户【' + userName + '】发起了待办', {
                                    icon: 1
                                }, function (i) {
                                    layer.close(i)
                                    location.reload()
                                    if (parent.$("#spsp").length > 0) {
                                        parent.layer.close(parent.$("#spsp").val())
                                        parent.location.reload()
                                    }
                                }
                            )
                        } else {
                            if (data.wfActivity!=null && data.wfActivity.activityCode!=undefined && data.wfActivity.activityCode == "end") {
                                layer.alert('流程' + title + '成功，流程已结束！', {
                                        icon: 1
                                    }, function (i) {
                                        layer.close(i)
                                        location.reload()
                                        if (parent.$("#spsp").length > 0) {
                                            parent.layer.close(parent.$("#spsp").val())
                                            parent.location.reload()
                                        }
                                    }
                                )
                            } else {
                                if (data.user == "null") {
                                    layer.msg('提交失败！下一活动办理人找不到！', {
                                        icon: 2,
                                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                                    }, function () {
                                    })
                                }else{
                                layer.alert('流程' + title + '成功！', {
                                        icon: 1
                                    }, function (i) {
                                        layer.close(i)
                                        location.reload()
                                        if (parent.$("#spsp").length > 0) {
                                            parent.layer.close(parent.$("#spsp").val())
                                            parent.location.reload()
                                        }
                                    }
                                )
                            }
                            }
                        }

                    }

                }
                else if(data.wfState == "over"){
                    layer.alert('请不要重复提交代办！', {
                            icon: 1
                        }, function (i) {
                            layer.close(i)
                            location.reload()
                            if (parent.$("#spsp").length > 0) {
                                parent.layer.close(parent.$("#spsp").val())
                                parent.location.reload()
                            }
                        }
                    )
                }
                else {
                    if (data.wfState != null && data.wfState != "") {
                        if (data.wfState == "NO") {
                            wfNull();
                        }
                        else {
                            if(wfTargetList!=""&&wfTargetList!=null) {
                                wfDuo(data.wfTargetList);
                            }
                            else{
                                layer.alert('流程异常！所找到的环节均没有办理人员！请尽快联系管理人员！', {
                                        icon: 1
                                    }, function (i) {
                                        layer.close(i);
                                        location.reload()
                                        if (parent.$("#spsp").length > 0) {
                                            parent.layer.close(parent.$("#spsp").val())
                                            parent.location.reload()
                                        }
                                    }
                                )
                            }
                        }
                    }
                    else if (data.user == "null") {
                        layer.msg('提交失败！下一活动办理人找不到！', {
                            icon: 2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                        })
                    }
                    else {
                        layer.msg('流程操作失败！', {
                            icon: 2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                        })
                    }
                }
            },
            error: function (data) {
                if (data.wfState != null && data.wfState != '') {
                    if (data.wfState == "NO") {
                        wfNull();
                    }
                    else {
                        layer.msg('流程操作失败！', {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                        })
                    }
                }
                else {
                    layer.msg('流程操作失败！', {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                    })
                }
            }
        });
    }
    $.each(parent.parent.$("#LAY_app_tabsheader li"), function (i, item) {
        // console.log($(this).attr("lay-id"));
        if ($(this).attr("lay-id") == './base/sysTask/MyTaskList.html?taskState=1') {
            parent.parent.$("[src='./base/sysTask/MyTaskList.html?taskState=1']").attr("src", './base/sysTask/MyTaskList.html?taskState=1')
        }
        if ($(this).attr("lay-id") == './base/workflow/doneIndex.html') {
            parent.parent.$("[src='./base/workflow/doneIndex.html']").attr("src", './base/workflow/doneIndex.html ')
        }
    });
}

//若找不到下一节点  然用户选择剩下的环节
//跳转
function wfNull() {
    var url = "wfNull.html?wfId=" + wfId + "&activityId=" + activityId + "&taskId=" + taskId;
    layer.open({
        type: 2,
        area: ['700px', '500px'],
        content: url,
        id: "layerNull",
        success: function (layero, index) {
            $("#layerNull").val(index)

        },
        end: function () {

        }
    });
}

//若找到多个下一节点  然用户选择剩下的环节
function wfDuo(wfActivity) {
    var wfact = JSON.stringify(wfActivity);
    $("#activity").val(wfact);
    var url = "wfDuo.html?taskId=" + taskId;
    layer.open({
        type: 2,
        area: ['700px', '500px'],
        content: url,
        id: "layerNull",
        success: function (layero, index) {
            $("#layerNull").val(index)

        },
        end: function () {

        }
    });
}

//查看流程
function selectWF() {
    var viewFlowchatUrl = "../wfMyWork/viewWorkFlow.html";
    var tab0 = {
        title: '流程进度',
        content: '<iframe id="viewWorkFlow" src="' + viewFlowchatUrl + '"\n' +
            'style="width: 100%; height: 100%; border:0;"\n' +
            'scrolling="no" wfId="' + wfId + '"></iframe>'
    }
        , arrTab = [];
    arrTab.push(tab0);
    layer.tab({
        area: ['100%', '100%'],
        tab: arrTab,
        success: function (layerObj, index) {

            $(".layui-layer-content").css("overflow-y", "hidden");

            iframeAutoFit("viewWorkFlow");

            $(window).resize(function () {
                iframeAutoFit("viewWorkFlow");
            });

        },
        end: function () {

        }
    });

    return false;
}

function iframeAutoFit(iframeId) {
    var iframe = document.getElementById(iframeId);
    if (iframe == null || iframe == "undefine" || iframe == "") return;
    iframe.style.width = (window.innerWidth - 20) + 'px';
    iframe.style.height = window.innerHeight + 'px';
}

//关闭结束提醒
function closeWF() {
    ActHttpRequest('/wf/task/update?id='+wfTaskId+'&wfTaskState='+2, {}, function (data) {
        if (data) {
            parent.layer.alert('提交成功！', function (index) {
                parent.location.reload()
                layer.close(index)
                if (parent.parent.$("#spsp").length > 0) {
                    parent.parent.layer.close(parent.$("#spsp").val())
                    parent.parent.location.reload()
                }
            })
        } else {
            layer.msg('流程操作失败！', {
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }
            )
        }
    });
}


//检测表单是否有 自定义编码字段 ， 并对应取得编码字段的值
//如果出现不同业务表、编码字段名相同的情况，需要进行代码修改
function replaceObjCode() {
    //扩展编码字段时，将字段英文名放入 codingFields
    var codingFields = ["proCoding", "clientCode", "ecNumber", "eoNumber"]

    codingFields.forEach(function (cf) {
        if ($("input[name=" + cf + "]").length > 0) {
            $("input[name=" + cf + "]").val(getRule(cf))
        }
    })
}